import java.net.*;
import java.io.*;

public class Receiver implements Runnable{
	public Server server=null;
	public Client client=null;
	public DatagramSocket mySocket;
	
	public Receiver(Server s){
		server = s;
		mySocket = server.mySocket;
	}
	
	public Receiver(Client c){
		client = c;
		mySocket = client.mySocket;
	}
	
	
	public void run(){
		try{
			byte[] buffer = new byte[20];
			while(true){
				DatagramPacket p = new DatagramPacket(buffer,20);
				mySocket.receive(p);
				if(client==null)server.showMsg(new String(p.getData()));
				if(server==null)client.showMsg(new String(p.getData()));
				System.out.println("pack: " + new String(p.getData()));
			}
		}catch(Exception e){System.err.println(e);}
	}

}
